<?php
global $_GPC, $_W;
$mokuai=pdo_get('zh_gjw_cusmanage',array('phone'=>$_W['username']));
$_W['uniacid']=$mokuai['uniacid'];
$GLOBALS['frames'] = $this->getNaveMenu();
$todaytime=strtotime(date('Y-m-d',time()));
$yesterdaytime=strtotime(date('Y-m-d',time()))-86400;
$weektime=strtotime(date('Y-m-d',time()))-7*86400;
$monthtime=strtotime(date('Y-m-d',time()))-30*86400;

$todays=pdo_fetchall("SELECT a.* FROM " . tablename('zh_gjw_orders'). " a"  . " left join " . tablename("zh_gjw_dbpublish") . " b on a.p_id=b.id WHERE  a.type=:type and b.phone=:phone and a.state=:state and timesjc>={$todaytime}", array(':type'=>1,':state'=>4,':phone'=>$_W['username']));
$todays+=pdo_fetchall("SELECT a.* FROM " . tablename('zh_gjw_orders'). " a"  . " left join " . tablename("zh_gjw_shotpublish") . " b on a.p_id=b.id WHERE  a.type=:type and b.phone=:phone and a.state=:state and timesjc>={$todaytime}", array(':type'=>2,':state'=>4,':phone'=>$_W['username']));
$todays+=pdo_fetchall("SELECT a.* FROM " . tablename('zh_gjw_orders'). " a"  . " left join " . tablename("zh_gjw_marketpublish") . " b on a.p_id=b.id WHERE  a.type=:type and b.phone=:phone and a.state=:state and timesjc>={$todaytime}", array(':type'=>3,':state'=>4,':phone'=>$_W['username']));
$todays+=pdo_fetchall("SELECT a.* FROM " . tablename('zh_gjw_orders'). " a"  . " left join " . tablename("zh_gjw_storepublish") . " b on a.p_id=b.id WHERE  a.type=:type and b.phone=:phone and a.state=:state and timesjc>={$todaytime}", array(':type'=>4,':state'=>4,':phone'=>$_W['username']));
$todaynum=count($todays);
if ($todaynum>0) {
	$todaymoneys=0;
	for ($i=0; $i <$todaynum ; $i++) { 
		$todaymoneys+=$todays[$i]['ofees'];
	}
	$todayavg=$todaymoneys/$todaynum;
}

$yesterdays=pdo_fetchall("SELECT a.* FROM " . tablename('zh_gjw_orders'). " a"  . " left join " . tablename("zh_gjw_dbpublish") . " b on a.p_id=b.id WHERE  a.type=:type and b.phone=:phone and a.state=:state and timesjc>={$yesterdaytime} and timesjc<{$todaytime}", array(':type'=>1,':state'=>4,':phone'=>$_W['username']));
$yesterdays+=pdo_fetchall("SELECT a.* FROM " . tablename('zh_gjw_orders'). " a"  . " left join " . tablename("zh_gjw_shotpublish") . " b on a.p_id=b.id WHERE  a.type=:type and b.phone=:phone and a.state=:state and timesjc>={$yesterdaytime} and timesjc<{$todaytime}", array(':type'=>2,':state'=>4,':phone'=>$_W['username']));
$yesterdays+=pdo_fetchall("SELECT a.* FROM " . tablename('zh_gjw_orders'). " a"  . " left join " . tablename("zh_gjw_marketpublish") . " b on a.p_id=b.id WHERE  a.type=:type and b.phone=:phone and a.state=:state and timesjc>={$yesterdaytime} and timesjc<{$todaytime}", array(':type'=>3,':state'=>4,':phone'=>$_W['username']));
$yesterdays+=pdo_fetchall("SELECT a.* FROM " . tablename('zh_gjw_orders'). " a"  . " left join " . tablename("zh_gjw_storepublish") . " b on a.p_id=b.id WHERE  a.type=:type and b.phone=:phone and a.state=:state and timesjc>={$yesterdaytime} and timesjc<{$todaytime}", array(':type'=>4,':state'=>4,':phone'=>$_W['username']));
$yesterdaynum=count($yesterdays);
if ($yesterdaynum>0) {
	$yesterdaymoneys=0;
	for ($i=0; $i <$yesterdaynum ; $i++) { 
		$yesterdaymoneys+=$yesterdays[$i]['ofees'];
	}
	$yesterdayavg=$yesterdaymoneys/$yesterdaynum;
}

$weeks=pdo_fetchall("SELECT a.* FROM " . tablename('zh_gjw_orders'). " a"  . " left join " . tablename("zh_gjw_dbpublish") . " b on a.p_id=b.id WHERE  a.type=:type and b.phone=:phone and a.state=:state and timesjc>={$weektime}", array(':type'=>1,':state'=>4,':phone'=>$_W['username']));
$weeks+=pdo_fetchall("SELECT a.* FROM " . tablename('zh_gjw_orders'). " a"  . " left join " . tablename("zh_gjw_shotpublish") . " b on a.p_id=b.id WHERE  a.type=:type and b.phone=:phone and a.state=:state and timesjc>={$weektime}", array(':type'=>2,':state'=>4,':phone'=>$_W['username']));
$weeks+=pdo_fetchall("SELECT a.* FROM " . tablename('zh_gjw_orders'). " a"  . " left join " . tablename("zh_gjw_marketpublish") . " b on a.p_id=b.id WHERE  a.type=:type and b.phone=:phone and a.state=:state and timesjc>={$weektime}", array(':type'=>3,':state'=>4,':phone'=>$_W['username']));
$weeks+=pdo_fetchall("SELECT a.* FROM " . tablename('zh_gjw_orders'). " a"  . " left join " . tablename("zh_gjw_storepublish") . " b on a.p_id=b.id WHERE  a.type=:type and b.phone=:phone and a.state=:state and timesjc>={$weektime}", array(':type'=>4,':state'=>4,':phone'=>$_W['username']));
$weeknum=count($weeks);
if ($weeknum>0) {
	$weekmoneys=0;
	for ($i=0; $i <$weeknum ; $i++) { 
		$weekmoneys+=$weeks[$i]['ofees'];
	}
	$weekavg=$weekmoneys/$weeknum;
}

$months=pdo_fetchall("SELECT a.* FROM " . tablename('zh_gjw_orders'). " a"  . " left join " . tablename("zh_gjw_dbpublish") . " b on a.p_id=b.id WHERE  a.type=:type and b.phone=:phone and a.state=:state and timesjc>={$monthtime}", array(':type'=>1,':state'=>4,':phone'=>$_W['username']));
$months+=pdo_fetchall("SELECT a.* FROM " . tablename('zh_gjw_orders'). " a"  . " left join " . tablename("zh_gjw_shotpublish") . " b on a.p_id=b.id WHERE  a.type=:type and b.phone=:phone and a.state=:state and timesjc>={$monthtime}", array(':type'=>2,':state'=>4,':phone'=>$_W['username']));
$months+=pdo_fetchall("SELECT a.* FROM " . tablename('zh_gjw_orders'). " a"  . " left join " . tablename("zh_gjw_marketpublish") . " b on a.p_id=b.id WHERE  a.type=:type and b.phone=:phone and a.state=:state and timesjc>={$monthtime}", array(':type'=>3,':state'=>4,':phone'=>$_W['username']));
$months+=pdo_fetchall("SELECT a.* FROM " . tablename('zh_gjw_orders'). " a"  . " left join " . tablename("zh_gjw_storepublish") . " b on a.p_id=b.id WHERE  a.type=:type and b.phone=:phone and a.state=:state and timesjc>={$monthtime}", array(':type'=>4,':state'=>4,':phone'=>$_W['username']));
$monthnum=count($months);
if ($monthnum>0) {
	$monthmoneys=0;
	for ($i=0; $i <$monthnum ; $i++) { 
		$monthmoneys+=$months[$i]['ofees'];
	}
	$monthavg=$monthmoneys/$monthnum;
}

include $this->template('web/cusdata');